home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / Newton Sample Code 1.1 / Views / Scroll Over-2 / ScrollPict.text < prev    next >
Encoding:
Text File  |  1994-03-08  |  6.3 KB  |  212 lines  |  [TEXT/MPS ]

  1.  
  2. // ---- End Project Data ----
  3.  
  4.  
  5. // ---- File ScrollPict.t ----
  6. ScrollingSample :=
  7.    {title: "Scrolling Sample",
  8.     viewBounds: {left: 0, top: 0, right: 240, bottom: 336},
  9.     _proto: protoApp,
  10.     debug: "ScrollingSample"
  11.    };
  12.  
  13. clipper1 := /* child of ScrollingSample */
  14.    {viewFlags: 545,
  15.     viewFormat: 337,
  16.     viewBounds: {left: 11, top: 27, right: 231, bottom: 157},
  17.     viewOriginX: 0,
  18.     viewOriginY: 0,
  19.     ScrollMe:
  20.       // This is the function that actually scrolls by using SetOrigin
  21.       // within the clipper1 window.  Any child views of the clipper1
  22.       // window will scroll.  (That's why the scroller controll isn't
  23.       // a child of the clipper1 window!)
  24.       
  25.       func(deltaX, deltaY)
  26.       begin
  27.          local x := viewOriginX + deltaX;
  28.          local y := viewOriginY + deltaY;
  29.       
  30.          if x > xMax then x := xMax;
  31.          if y > yMax then y := yMax;
  32.       
  33.          if x < 0 then x := 0;
  34.          if y < 0 then y := 0;
  35.       
  36.          :SetOrigin(x, y);   // also Dirties the view.
  37.          RefreshViews();
  38.       end,
  39.     xMax: nil,
  40.     yMax: nil,
  41.     viewSetupDoneScript:
  42.       func()
  43.       begin
  44.          xMax := viewWithPict1:LocalBox().right - clipper1:LocalBox().right;
  45.          yMax := viewWithPict1:LocalBox().bottom - clipper1:LocalBox().bottom;
  46.       end,
  47.     viewClickScript:
  48.       func(unit)
  49.       begin
  50.          local startX := GetPoint(firstX, unit);
  51.          local startY := GetPoint(firstY, unit);
  52.          local deltaX;
  53.          local deltaY;
  54.          
  55.          InkOff(unit);
  56.          PlaySound(ROM_click);
  57.          repeat
  58.             deltaX := startX - GetPoint(finalX, unit);
  59.             startX := GetPoint(finalX, unit);
  60.             deltaY := startY - GetPoint(finalY, unit);
  61.             startY := GetPoint(finalY, unit);
  62.             :ScrollMe(deltaX, deltaY);
  63.          until StrokeDone(unit);
  64.          TRUE;
  65.       end,
  66.     viewclass: 74,
  67.     debug: "clipper1"
  68.    };
  69. // View clipper1 is declared to ScrollingSample
  70.  
  71. viewWithPict1 := /* child of clipper1 */
  72.    {viewFlags: 1,
  73.     icon: GetPictAsBits("Black World Map", nil),
  74.     viewFormat: 256,
  75.     viewBounds: {top: 0, left: 0, right: 360, bottom: 180},
  76.     viewclass: 76,
  77.     debug: "viewWithPict1"
  78.    };
  79. // View viewWithPict1 is declared to ScrollingSample
  80.  
  81.  
  82.  
  83.  
  84.  
  85. scrollCompass := /* child of ScrollingSample */
  86.    {viewFlags: 513,
  87.     viewFormat: 0,
  88.     viewBounds: {left: 12, top: 124, right: 44, bottom: 156},
  89.     viewClickScript:
  90.       // This function is called when the pen is down in the
  91.       // scroller controll, and it calls clipper1:ScrollMe to
  92.       // move the window around.  Ideally this view should have
  93.       // its mask set, and if fact the mask is in the resource
  94.       // file, but NTK isn't dealing with the mask properly yet.
  95.       
  96.       func(unit)
  97.       begin
  98.          local deltaX, deltaY;
  99.       
  100.          InkOff(unit);
  101.          PlaySound(ROM_click);
  102.       
  103.          repeat
  104.             // compute where in the view the pen is currently and scroll in the right
  105.             // direction.  The values 12 and 20 are pretty arbitrary.
  106.             deltaX := if GetPoint(finalX, unit) < viewBounds.left + 12 then -16
  107.                      else if GetPoint(finalX, unit) > viewBounds.left + 20 then 16
  108.                      else 0;
  109.       
  110.             deltaY := if GetPoint(finalY, unit) < viewBounds.top + 12 then -16
  111.                      else if GetPoint(finalY, unit) > viewBounds.top + 20 then 16
  112.                      else 0;
  113.             clipper1:ScrollMe(deltaX, deltaY);
  114.          until StrokeDone(unit);
  115.         
  116.          TRUE;
  117.       end,
  118.     icon: GetPictAsBits("Scroll2D", 1),
  119.     viewclass: 76,
  120.     debug: "scrollCompass"
  121.    };
  122.  
  123. // After Script for "scrollCompass"
  124. thisView := scrollCompass;
  125. thisView.viewTransferMode := modeMask;
  126.  
  127.  
  128.  
  129. clipper2 := /* child of ScrollingSample */
  130.    {viewFlags: 33,
  131.     viewFormat: 337,
  132.     viewBounds: {top: 170, left: 10, right: 230, bottom: 300},
  133.     declareSelf:
  134.       'base
  135.       
  136.       // this needs to be here so the cannonicalCompass knows
  137.       // which view to dirty as part of the redraw.,
  138.     viewclass: 74,
  139.     debug: "clipper2"
  140.    };
  141. // View clipper2 is declared to ScrollingSample
  142.  
  143. viewWithPict2 := /* child of clipper2 */
  144.    {viewFlags: 1,
  145.     icon: GetPictAsBits("White World Map", nil),
  146.     viewFormat: 256,
  147.     viewBounds: {left: 0, top: 0, right: 360, bottom: 180},
  148.     viewSetupDoneScript:
  149.       func()
  150.       begin
  151.          // set up the canonicalCompass to scroll this view.
  152.          canonicalCompass.scrolledView := self;
  153.          
  154.          // the canonicalCompass expects dataBounds to be a slot
  155.          // with a bounds frame containing the size of the data that
  156.          // needs to be scrolled.  Just use the viewBounds.
  157.          self.dataBounds := viewBounds;
  158.       
  159.          // NOTE:  NTK should be setting the viewBounds for this
  160.          // view to match the size of the picture in the resource
  161.          // file.  Currently it doesn't, so the viewBounds was
  162.          // just typed in.  It would have been possible to use the
  163.          // PictBounds global function (at compile time) to get
  164.          // the size of the picture resource, but I'm lazy.
  165.       
  166.          // NOTE 2: viewOriginX and viewOriginY are supposed to be
  167.          // created and set by the view system, but it's set up to
  168.          // save memory and treat NIL as 0.  However, the canonicalCompass
  169.          // doesn't handle that case, so we have to create the
  170.          // viewOriginX and viewOriginY slots ourself and initialize
  171.          // them to 0.
  172.          self.viewOriginX := 0;
  173.          self.viewOriginY := 0;
  174.       end,
  175.     viewclass: 76,
  176.     debug: "viewWithPict2"
  177.    };
  178. // View viewWithPict2 is declared to ScrollingSample
  179.  
  180.  
  181.  
  182. canonicalCompass := /* child of clipper2 */
  183.    {
  184.     scrolledView:
  185.       // will be set to the view to be scrolled
  186.       // in the viewWithPict2's viewSetupDoneScript.
  187.       
  188.       nil;,
  189.     _proto: protoTextButton,
  190.     debug: "canonicalCompass"
  191.    };
  192. // View canonicalCompass is declared to ScrollingSample
  193.  
  194. // After Script for "canonicalCompass"
  195. thisView := canonicalCompass;
  196. thisView._proto := ROM_canonicalcompass;
  197.  
  198. // this script is called at COMPILE TIME after the view has been compiled
  199. // It's currently the only way to set the _proto slot with the 1.0b4
  200. // NTK.  The canonicalCompass proto isn't in the NTK library just yet.
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210. // ---- Beginning of section for non used Layout files ----
  211.  
  212. // End of output